// parts GRUB

exports.read = function (req, res) {
    console.log('--------Part read');

    exports.model.Part.find({}, function (err, rec) {
        if(err) {
            res.send({success: false});
        }
        else {
            res.send({success: true, Part: rec});
        }
    });
};

exports.add = function (req, res) {
    //console.log('--------Part add params=');
    var params = req.body;
    var part = new exports.model.Part(params);

    part.save(function(err) {
        if(err) {
            res.send({success: false});
        }
        else {
            res.send({success: true, Part: part});
        }
    });
};

exports.update = function (req, res) {
    console.log('--------Part update');
    var params = req.body;
    var id = params._id;

    //remove id from values to update
    delete params._id;

    exports.model.Part.update({ '_id': id}, { $set : params}, { upsert: false }, function (err) {
        if(err) {
            res.send({success: false});
        }
        else {
            res.send({success: true});
        }
    });
};

exports.destroy = function (req, res) {
    console.log('--------Part destroy');
    var params = req.body;

    exports.model.Part.remove({ '_id': params._id }, function (err) {
        if(err) {
            res.send({success: false});
        }
        else {
            res.send({success: true});
        }
    });
};
